package com.learn.demo.service.impl;

import com.learn.demo.dao.AsyncTransactionalMapper;
import com.learn.demo.entity.TestA;
import com.learn.demo.entity.TestB;
import com.learn.demo.service.TestAsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * TestAsyncServiceImpl
 *
 * @author banjiawei
 * @date 2022/01/10
 */
@Service
public class TestAsyncServiceImpl implements TestAsyncService {

    @Autowired
    private AsyncTransactionalMapper asyncTransactionalMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertTestA() {
        asyncTransactionalMapper.insertTestA();
    }

    @Override
    public List<TestA> listA() {
        return asyncTransactionalMapper.listA();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertTestB() {
        asyncTransactionalMapper.insertTestB();
        int a = 1/0;
    }

    @Override
    public List<TestB> listB() {
        return asyncTransactionalMapper.listB();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertTestAB() {
        insertTestA();
        insertTestB();
    }
}
